package cn.gailvlun.gll.listener;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.util.Log;

import com.blankj.utilcode.util.ActivityUtils;

import cn.gailvlun.gll.util.LogUtil;



public abstract class GroundListener implements Application.ActivityLifecycleCallbacks {

    public abstract void onForeground(Activity activity);
    public abstract void onBackground(Activity activity);

    private int foregroundCount = 0; 
    private int bufferCount = 0; 

    @Override
    public void onActivityStarted(Activity activity) {
        if (foregroundCount <= 0) {
            
            onForeground(activity);
        }
        if (bufferCount < 0) {
            bufferCount++;
        } else {
            foregroundCount++;
        }
    }

    @Override
    public void onActivityStopped(Activity activity) {
        if (activity.isChangingConfigurations()) { 
            bufferCount--;
        } else {
            foregroundCount--;
            if (foregroundCount <= 0) {
                
                onBackground(activity);
            }
        }
    }

    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
    }

    @Override
    public void onActivityResumed(Activity activity) {
    }

    @Override
    public void onActivityPaused(Activity activity) {
    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
    }

    @Override
    public void onActivityDestroyed(Activity activity) {
    }
}
